package com.neu.service;

import com.github.pagehelper.PageHelper;
import com.neu.dao.ShoppingIssueMapper;
import com.neu.domain.ShoppingAdExample;
import com.neu.domain.ShoppingIssue;
import com.neu.domain.ShoppingIssueExample;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;

@Service
public class ShoppingIssueService {
   @Autowired
   private ShoppingIssueMapper shoppingIssueMapper;
   public void add(ShoppingIssue record) {
	   record.setAddTime(LocalDateTime.now());
	   record.setUpdateTime(LocalDateTime.now());
	   shoppingIssueMapper.insertSelective(record);
   }
   public void deleteById(Integer id) {
	  shoppingIssueMapper.logicalDeleteByPrimaryKey(id);
   }
   public int updateById(ShoppingIssue record) {
	   record.setUpdateTime(LocalDateTime.now());
	   return shoppingIssueMapper.updateByPrimaryKeySelective(record);
   }
   public List<ShoppingIssue> querySelective(String question, String answer, Integer page, Integer limit, String sort, String order){
	   ShoppingIssueExample example=new ShoppingIssueExample();
	   ShoppingIssueExample.Criteria criteria = example.createCriteria();

       if (!StringUtils.isEmpty(question)) {
           criteria.andQuestionLike("%" + question + "%");
       }
       if (!StringUtils.isEmpty(answer)) {
           criteria.andAnswerLike("%" + answer + "%");
       }
       criteria.andDeletedEqualTo(false);

       if (!StringUtils.isEmpty(sort) && !StringUtils.isEmpty(order)) {
           example.setOrderByClause(sort + " " + order);
       }

       PageHelper.startPage(page, limit);
       return shoppingIssueMapper.selectByExample(example);
	
   }
}
